package com.ai.trickycards.ui.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import com.ai.trickycards.databinding.DialogGameQuitBinding

class GameQuitDialog(
    context: Context,
    private val quitBlock: () -> Unit
) : Dialog(context) {

    private val binding by lazy {
        DialogGameQuitBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        setCanceledOnTouchOutside(false)
        setCancelable(false)
        window?.let {
            it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
            val displayMetrics = context.resources.displayMetrics
            it.attributes.width = (displayMetrics.widthPixels - 48 * displayMetrics.density).toInt()
        }

        binding.tvCancel.setOnClickListener {
            dismiss()
        }
        binding.tvQuit.setOnClickListener {
            dismiss()
            quitBlock.invoke()
        }
    }
}